package com.cake.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cake.base.util.ReturnUtils;
import com.cake.entity.XxShippingMethod;
import com.cake.service.inter.IXxShippingMethodService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * 配送方式控制器
 * @author Administrator
 *
 */
@RestController
@RequestMapping(value = "shippingMethod")
public class ShippingMethodController {

	@Autowired
	private IXxShippingMethodService xxShippingMethodService;
	
	/**
	 * 查询所有的配送方式
	 * @return
	 * @throws Exception 
	 */
	@PostMapping(value = "selectShippingMethods")
	public Object selectShippingMethods(@RequestBody XxShippingMethod xxShippingMethod) throws Exception{
		PageHelper.startPage(xxShippingMethod.getCurrentPage(), xxShippingMethod.getPageSize());
		List<XxShippingMethod> list = xxShippingMethodService.selectByAttributeAnd(new XxShippingMethod());
		PageInfo<XxShippingMethod> page = new PageInfo<>(list);
		return ReturnUtils.forNoramlPage("000000", list, 
				page.getPageNum(), page.getPageSize(), page.getPages(), (int)page.getTotal());
	}
	
	/**
	 * 根据id查询一条配送方式详情
	 * @return
	 * @throws Exception 
	 */
	@GetMapping(value = "selectsShippingMethodById")
	public Object selectsShippingMethodById(Long shippingMethodId) throws Exception{
		return ReturnUtils.forNoramlSuccess(xxShippingMethodService.selectByPrimaryKey(shippingMethodId));
	}
	
	/**
	 * 添加一条配送方式
	 * @return
	 * @throws Exception 
	 */
	@PostMapping(value = "insertShippingMethod")
	public Object insertShippingMethod(@RequestBody XxShippingMethod xxShippingMethod) throws Exception{
		return ReturnUtils.forNoramlSuccess(xxShippingMethodService.insertSelective(xxShippingMethod));
	}
	
	/**
	 * 修改配送方式
	 * @param xxShippingMethod
	 * @return
	 * @throws Exception 
	 */
	@PostMapping(value = "updateShippingMethod")
	public Object updateShippingMethod(@RequestBody XxShippingMethod xxShippingMethod) throws Exception{
		return ReturnUtils.forNoramlSuccess(xxShippingMethodService.updateByPrimaryKeySelective(xxShippingMethod));
	}
}
